import React from 'react';

export default class DeliverySettingList extends React.Component {
  constructor(props) {
    super(props)
  }

  renderList() {
    var self = this;
    var content = [];
    if (this.props.data && this.props.data.length > 0) {
      this.props.data.forEach(function(data, index) {
        // console.log(data)
        var time = new Date(data.created_at);
        var contentData = {};
        try {
          var jsonStr = data.content,
              contentData = JSON.parse(jsonStr);
        } catch (e) {

        }
        var date;
        if (time) {
          date = time.toLocaleString();
        }
        var status = data.status;
        var statusStr;
        if (status == "unreceive") {
          statusStr = "已发送"
        }else if (status == "has_receive") {
          statusStr = "已接受"
        }

        content.push((
          <tr>
            <td>{data.unit.unit_number}</td>
            <td>{contentData.keyword1.value || ""}</td>
            <td>{contentData.keyword2.value || ""}</td>
            <td>{date}</td>
            <td>{statusStr}</td>
          </tr>
        ))
      })
    }

    return content
  }

  render() {
    return(
      <div className="Delivery-setting-list setting-list">
        <table className="table">
          <thead>
            <tr className="table-title">
              <th>户号</th>
              <th>单号</th>
              <th>收件人</th>
              <th>日期</th>
              <th>状态</th>
            </tr>
          </thead>
          <tbody>
            {this.renderList()}
          </tbody>
        </table>
      </div>
    )
  }
}
